#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP

#include <QMainWindow>
#include <qmap.h>
#include <QtDBus>
#include <qtableview.h>
#include "servicesproxymodel.h"
#include "dbusobjmodel.hpp"
#include "dbusmethodmodel.hpp"
//#include "DbusTestModel.hpp"
#include "dragdropmodel.h"
#include "common.hpp"
#include "dbuscaller.hpp"

#include "checkboxdelegate.hpp"
#include "dbusSignalmodel.hpp"

struct DbusTestCopyItem
{
    DbusTestModelItem *parent;
    BusSignatureEx m_data;
    QList<DVariant> dbusArgs;
    bool m_skip;
};
Q_DECLARE_METATYPE(DbusTestCopyItem)

class QDBusViewer;
class DbusMethodModel;
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
public slots:
    void addDevice();
    void delDevice();

    void about();
private slots:
    void on_customContextMenuRequested(const QPoint &pos);
    void on_customContextMenuRequested1(const QPoint &pos);
    void on_customContextMenuRequested2(const QPoint &pos);

    void onCustomContextTriggered(QAction *action);
    void onCustomContextTriggered1(QAction *action);
     void onCustomContextTriggered2(QAction *action);

    void objectSelectionChanged(const QItemSelection &index);
    void testSelectionChanged(const QItemSelection &index);
    void methodSelectionChanged(const QItemSelection &index);

    void activate(const QModelIndex &item);

    void dumpMessage(const QDBusMessage &message);
    void signalMessage(DbusTestModelItem *item,const QDBusMessage &message);
    void onDbusCallItemStart(DbusTestModelItem *item, int row);
    void onDbusCallItemFinish(DbusTestModelItem *item, int row,int loops, QVariant msg);
    void onDbusCallStart();
    void onDbusCallFinish();
    void onDbusResetResult(int row);

    void on_tvTest_activated(const QModelIndex &index);

    void on_actionCopyClicked();
    void on_actionExportClicked();
    void on_actionImportClicked();
    void on_actionPasteClicked();
    void on_actionStepClicked();
    void on_actionLoopClicked();
    void on_actionStopClicked();
    void on_actionAddClicked();
    void on_actionUpClicked();
    void on_actionDownClicked();
    void on_actionDelClicked();
    void on_actionRunClicked();
    void on_actionExitClicked();



    void noRunlogNameChange(const QString &path,const QString &prefix , const QString &filename);
    void noSignallogNameChange(const QString &path,const QString &prefix , const QString &filename);

private:
    void enbleAction();
    void saveState() const;

    void restoreSettings();

    QToolBar *deviceToolBar;
    QToolBar *fileToolBar;
    QToolBar *runToolBar;
    QToolBar *editToolBar;

    QMap<QString,QDBusViewer *> viewList;
    Ui::MainWindow *ui;


    DbusObjModel *dbusObjModel;
    QSortFilterProxyModel *dbusObjProxyModel;
    QMenu *m_DbusObjectView_customContextMenu;

    DbusMethodModel *dbusmethodmodel;
    QSortFilterProxyModel *dbusmethodProxyModel;

    DragDropModel *m_testModel;

    QMenu *m_testView_customContextMenu;
    QMenu *m_signalView_customContextMenu;

    DbusSignalModel *m_signalModel;


    DbusCaller m_dbusCaller;

    QRegExp objectPathRegExp;
    QMenu* tableHeaderMenu(QTableView *table);
    void setupDragDrop(QTableView *tableView);

    QString m_logfile;
    QString m_signalfile;

    // QWidget interface
protected:
    void closeEvent(QCloseEvent *event) override;
};



#endif // MAINWINDOW_HPP
